/**
 * @file Define applicaiton controller for all application related functions
 * 
 * @author Steve Gao<gaofu@parllay.com>
 */
const WebBaseController     = require('./web-base-controller');
const {SystemServices}      = require('../../constants');

class ApplicationController extends WebBaseController {

    get i18nSerivice() {
        if (!this._i18nService) {
            this._i18nService = this.getSystemService(SystemServices.I18N_SERVICE);
        }

        return this._i18nService;
    }

    get name() {
        return 'ApplicationController';
    }

    get handlersPath() {
        return 'application';
    }

    getLocaleResources(request, namespace, parentCallback) {
        let me = this;
        let languages = request.languages || ['zh-CN', 'en'];
        let resources = {};
        languages.forEach((lang) => {

            let rs = me.i18nSerivice.getResourcesByLanguage(lang, namespace);
            resources[lang] = {
                translation: rs
            };
        });

        parentCallback(resources);
    }
}

exports.ApplicationController = ApplicationController;